﻿// ------------------------------------------------------------------------------------
//      Copyright (c) 2012 uhavemyword@gmail.com. All rights reserved.
//      Created by Ben at 12/24/2012 7:13:16 PM
// ------------------------------------------------------------------------------------

namespace CP.NLayer.Models.Entities
{
    using CP.NLayer.Models.LocalizedDataAnnotations;
    using System;
    using System.ComponentModel.DataAnnotations;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.Runtime.Serialization;

    [DataContract(IsReference = true)]
    public abstract class EntityBase : ModelBase
    {
        private DateTime? _creationTime;

        public EntityBase()
        {
            this.Id = Guid.NewGuid().ToString();
        }

        [DataMember]
        [Key]
        public string Id { get; set; }

        [DataMember]
        public DateTime CreatedOnUtc
        {
            get { return _creationTime.HasValue ? _creationTime.Value : DateTime.UtcNow; }
            set { _creationTime = value; }
        }

        [DataMember]
        public DateTime? UpdatedOnUtc { get; set; }

        [DataMember]
        [Timestamp]
        public byte[] RowVersion { get; set; }
    }
}
